package Translate;

import java.util.List;

import Absyn.MiniJava.Stm;
import Translate.Temp.Label;

public class HashRecord {
	public HashRecord next;
	public Label testLabel;
	public Label bodyLabel;
	public Label nextJump;
	public boolean amIDefault = false;
	public Translate.Tree.Exp valueExpression;
	List<Stm> statements;
	public HashRecord(){
		bodyLabel = new Label();
	}
	public Tree.Stm resolve(Absyn.MiniJava.Visitor<Void, Exp> vistor, Void d,HashRecord defaultNode,Label currentExit,
			Translate.Tree.Exp switchExpression){
		Tree.Stm stat;
		if(!amIDefault){
			stat = MiniJava.LABEL(testLabel);
			if(next!=null){
				stat = MiniJava.SEQ(stat,new Tree.Stm.CJUMP(Tree.Stm.CJUMP.Operator.BEQ,switchExpression,valueExpression,bodyLabel,next.testLabel));
			}
			else{
				if(defaultNode!=null)
					stat = MiniJava.SEQ(stat,new Tree.Stm.CJUMP(Tree.Stm.CJUMP.Operator.BEQ,switchExpression,valueExpression,bodyLabel,defaultNode.bodyLabel));
				else{
					stat = MiniJava.SEQ(stat,new Tree.Stm.CJUMP(Tree.Stm.CJUMP.Operator.BEQ,switchExpression,valueExpression,bodyLabel,currentExit));
				}
			}

			stat = MiniJava.SEQ(MiniJava.LABEL(bodyLabel));
		}
		else{
			stat = MiniJava.SEQ(MiniJava.LABEL(bodyLabel));
		}
		for(Stm s:statements){
			stat = MiniJava.SEQ(stat,s.accept(vistor, d).unNx());
		}
		stat = MiniJava.SEQ(stat,MiniJava.JUMP(nextJump));
		return stat;
	}

}

